/**
* Definition for singly - linked list.
* struct ListNode {
    *int val;
    *struct ListNode* next;
    *
};
*/
typedef struct ListNode ListNode;
struct ListNode* mergeTwoLists(struct ListNode* list1, struct ListNode* list2)
{
    if (list1 == NULL && list2 == NULL)
        return NULL;
    if (list1 == NULL)
        return list2;
    if (list2 == NULL)
        return list1;
    ListNode* newlisthead;
    ListNode* newlistpcur = (ListNode*)malloc(sizeof(ListNode));
    newlistpcur->val = 0;
    newlisthead = newlistpcur;
    while (list1 && list2)
    {

        if (list1->val < list2->val)
        {
            newlistpcur->next = list1;
            list1 = list1->next;
            newlistpcur = newlistpcur->next;
        }
        else
        {
            newlistpcur->next = list2;
            list2 = list2->next;
            newlistpcur = newlistpcur->next;
        }
    }
    if (list1)
    {
        newlistpcur->next = list1;
    }
    else
    {
        newlistpcur->next = list2;
    }
    return newlisthead->next;


}